// pages/product/SpellGroupDetails.js
var Zan = require('../../dist/index');
var WxParse = require('../../wxParse/wxParse.js');
let WxNotificationCenter = require('../../utils/WxNotificationCenter.js');
let network = null;
let utils = null;
let api = null;
const app = getApp();
function countdown(that) {
  for (var i = 0; i < that.data.groupList.length; i++) {
    var EndTime = that.data.groupList[i].endDate * 1000 || [];
    var NowTime = new Date().getTime();
    var total_micro_second = EndTime - NowTime || [];
    // 渲染倒计时时钟
    that.data.groupList[i].clock = dateformat(total_micro_second)
    // that.setData({
    //   clock: dateformat(total_micro_second)
    // });
    if (total_micro_second <= 0) {
      that.data.groupList[i].clock = "已经截止"
      //return;
    }
  }
  that.setData({
    groupList: that.data.groupList
  })
  
  // console.log(that.data.groupList);
  if (total_micro_second > 0){
    setTimeout(function () {
      total_micro_second -= 1000;
      countdown(that);
    }, 1000)
  }
  
}

// 时间格式化输出，如11:03 25:19 每1s都会调用一次
function dateformat(micro_second) {
  // 总秒数
  var second = Math.floor(micro_second / 1000);
  // 天数
  var day = Math.floor(second / 3600 / 24) < 10 ? '0' + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  // 小时
  var hr = Math.floor(second / 3600 % 24) < 10 ? '0' + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  // 分钟
  var min = Math.floor(second / 60 % 60) < 10 ? '0' + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  // 秒
  var sec = Math.floor(second % 60) < 10 ? '0' + Math.floor(second % 60) : Math.floor(second % 60);
  let date = '';
  if (day == 0) {
    date = hr + ":" + min + ":" + sec;
  } else {
    date = day + ":" + hr + ":" + min + ":" + sec;
  } 
  return date;
}
Page(Object.assign({}, Zan.TopTips, Zan.Toast, {

  /**
   * 页面的初始数据
   */
  data: {
    shared: true,
    product: {},
    listSpec: [],
    showDialog: false,
    count: 0,
    radioCheckVal01: '',
    radioCheckVal02: '',
    radioCheckVal03: '',
    intelvalue01: 0,
    intelvalue02: 0,
    intelvalue03: 0,
    isClickSpecification1: 0,
    isClickSpecification2: 0,
    isClickSpecification3: 0,
    item01: '',
    item02: '',
    item03: '',
    specId: '',
    nowclock: '',
    selectedSpec: null,
    specName: '',
    RealListspec: {},
    price: 0,
    distributorId: "",
    spellGroup: null,
    spellGroupId: '',
    userid:'',
    userSpellGroupId: '',
    mobile: null,
    groupCount: 0,
    formId: '',
    groupList:[],
    iscantuan:0,
    isSharetuan:0,
    groupPrice: 0,
    currentPrice: 0,
    limitCount: 0,
    storeCount: 0,
    unigroupId:'',
    canIUseMobile: wx.canIUse('button.open-type.getPhoneNumber')
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    network = new app.NetWorkUtils();
    utils = new app.Utils();
    api = new app.Api();
    if (options.storeInfo) {
      app.globalData.store = JSON.parse(decodeURIComponent(options.storeInfo));
      this.setData({
        store: app.globalData.store
      })
      console.log("===========product===========");
      console.log(app.globalData.store);
      console.log(this.data.store);
      console.log(this.data.store.id);
      
    }
    if (app.globalData.userId) {
      bind(options);
    } else {
      // 由于 openId 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoCallback = res => {
        bind(options);
      }
    }

    wx.showShareMenu({
      withShareTicket: true //要求小程序返回分享目标信息
    })
    /**
     * 获取个人及商家信息
     */
    if (app.globalData.userAndTenantInfo) {
      this.setData({
        mobile: app.globalData.userAndTenantInfo.mobile
      })
    }

    // wx.getUserInfo({
    //   success: res => {
    //     this.setData({
    //       nickName: res.userInfo.nickName,
    //     })
    //   }
    // })
    if (options.shared) {
      //存在shared表示别人分享过来的
      console.log('============shared==============');
      this.setData({
        sharedUserId: options.shared
      })
    }
    
    this.setData({
      spellGroupId: options.spellGroupId,
      userid: app.globalData.userId,
      bananer: {
        autoplay: true,
        interval: 5000,
        duration: 300,
        indicatorDots: true,
        circular: true,
        height: utils.windowSize().winWidth / 750 * 560
      }
    })
    if (!app.globalData.store) {
      let that = this;
      wx.getLocation({
        type: 'wgs84',
        success: function (res) {
          let latitude = res.latitude;
          let longitude = res.longitude;
          that.setData({
            lng: longitude,
            lat: latitude
          })
          network._post_json(that, api.nearbyStore, { lng: longitude, lat: latitude }, successStore);
        },
        fail: function (res) {
          console.log("拒绝获取地理位置++++++++++++++++++");
          that.setData({
            lng: 114.31171,
            lat: 30.59868
          })
          network._post_json(that, api.nearbyStore, { lng: that.data.lng, lat: that.data.lat }, successStore);
        }
      })
    }
    //network._post_json(this, api.getProductDetails, { productId: options.productId }, detailsSuccess);
    //network._post_json(this, api.groupRule, { spellgroupId: this.data.spellGroupId }, ruleSuccess);
    // 注册列表刷新事件
    WxNotificationCenter.addNotification("groupRefreshNotification", this.refreshNotification, this);
    this.onPullDownRefresh();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    WxNotificationCenter.removeNotification("groupRefreshNotification", this);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    network._post_json(this, api.SpellGroupDetail, { id: this.data.spellGroupId }, detailsSuccess);

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '花' + this.data.product.product.groupPrice / 100 + '元，就能拼得原价' + this.data.product.product.currentPrice / 100 + '元的【' + this.data.product.product.title + '】，太超值了',
      path: '/pages/product/SpellGroupDetails?shared=' + app.globalData.userId + '&productId=' + this.data.product.product.id + '&spellGroupId=' + this.data.product.id + '&storeInfo=' + encodeURIComponent(JSON.stringify(app.globalData.store)),
      imageUrl: this.data.product.product.imgUrl,
      success: function (res) {
        // 转发成功
        // if (res.shareTickets) {
        //   wx.getShareInfo({
        //     shareTicket: res.shareTickets,
        //     success: function (res) {
        //       network._post_json(this, api.updateFxcs, { directShareNums: 0, directShareQunNums: 1 }, fxcsSuccess);
        //     },
        //     fail: function (res) {
        //       // 转发失败
        //       network._post_json(this, api.updateFxcs, { directShareNums: 1, directShareQunNums: 0 }, fxcsSuccess);
        //     }
        //   })
        // } else {
        //   network._post_json(this, api.updateFxcs, { directShareNums: 1, directShareQunNums: 0 }, fxcsSuccess);
        // }

      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  gohome: function () {
    wx.switchTab({
      url: '/pages/home/Home',
    })
  },
  /**
   * 弹出框开关
   */
  Specclose: function (e) {
    this.setData({
      specDialog: !this.data.specDialog,
    })
  },
  refreshNotification:function(){
    this.setData({
      sharedUserId: '',
      isSharetuan: 0
    })
    this.onPullDownRefresh();
  },


  /* *****************************选择规格***************************** */
  //规格显示
  selectSpec: function (e) {
    var title = e.currentTarget.dataset.title;
    var productId = e.currentTarget.dataset.id;
    this.data.specArr = JSON.parse(this.data.product.product.spec);

    let specArrCon = [];
    for (var n = 0; n < this.data.specArr.length; n++) {
      let spec = {};
      let specDetailArr = [];
      spec.specType = this.data.specArr[n].specType;
      for (var i = 0; i < this.data.specArr[n].specDetails.length; i++) {
        let specDetail = {};
        specDetail.name = this.data.specArr[n].specDetails[i];
        specDetail.class = '';
        if (i == 0) {
          specDetail.class = "active";
        }
        specDetailArr.push(specDetail);
      }
      specArrCon.push(spec);
      spec.specDetails = specDetailArr;
    }

    this.setData({
      specTitle: title,
      specArrCon: specArrCon,
      specDialog: !this.data.specDialog,
      productId: productId,
      specDetails1: specArrCon[0].specDetails[0].name,
      specDetails2: specArrCon[1] != undefined ? specArrCon[1].specDetails[0].name : '',
      specDetails3: specArrCon[2] != undefined ? specArrCon[2].specDetails[0].name : '',
      groupPrice: this.data.groupPrice

    })

    if (this.data.count < 1) {
      this.data.count = 1;
      this.setData({
        count: this.data.count,
      });
    }

    getProductPrice(this);
  },
  //选择一个规格后
  specSelect: function (e) {
    console.log(this.data.specArrCon);
    var currData = e.currentTarget.dataset;
    var fatidx = currData.fatidx;
    var subidx = currData.subidx;
    var currBind = this.data.specArrCon[fatidx].specDetails[subidx];
    currBind.class = "active";
    //处理当前选择的规格类型的其他规格
    for (var n = 0; n < this.data.specArrCon[fatidx].specDetails.length; n++) {
      if (this.data.specArrCon[fatidx].specDetails[n].class == "active" && subidx != n) {
        this.data.specArrCon[fatidx].specDetails[n].class = "";
      }
    }

    this.setData(this.data);
    //计算所选规格价格
    var selectedSpec = [];
    for (var m = 0; m < this.data.specArrCon.length; m++) {
      for (var n = 0; n < this.data.specArrCon[m].specDetails.length; n++) {
        if (this.data.specArrCon[m].specDetails[n].class == "active") {
          selectedSpec.push(this.data.specArrCon[m].specDetails[n].name);
        }
      }
    }

    this.setData({
      specDetails1: selectedSpec[0],
      specDetails2: selectedSpec[1] != undefined ? selectedSpec[1] : '',
      specDetails3: selectedSpec[2] != undefined ? selectedSpec[2] : '',
    })
    getProductPrice(this);
  },
  /* *****************************选择规格end***************************** */

  /**
   * 减商品数量
   */
  reduce: function (e) {
    if (this.data.count > 1) {
      this.data.count--;
      this.setData({
        count: this.data.count,
      });
    }
  },
  /**
   * 加商品数量
   */
  add: function (e) {
    var counts = parseInt(this.data.count) + 1;
    //校验数量
    var checkFlag = isSelectedOk(this, this.data.product.product, counts);
    if (checkFlag == -1) {
      this.showZanTopTips(this.prompt, "库存不足");
      return false;
    } else if (checkFlag == -2) {
      this.showZanTopTips(this.prompt, "购买数量大于限购数量");
      return false;
    } else {
      this.data.count++;
      this.setData({
        count: this.data.count,
      });
    }

  },
  

  /**
   * 如果用户已授权，并且用户昵称不为空，则直接弹框
   */
  // chooseSpan: function (e) {
  //   if (this.data.product.isVirtual == 0 && this.data.product.isActive == 1) {
  //     this.setData({
  //       showDialog: true,
  //     });
  //   } else {
  //     this.showZanTopTips('商品已下架');
  //   }
  // },

  chooseSpan: function (e) {
    var event = e.currentTarget.dataset.event;
    if(this.data.count <= 0){
      this.showZanTopTips(this.prompt, '请先选择数量！');
      return false;
    }
    //跳到支付页
    this.setData({
      showDialog: false,
    });
    // 先判断此用户是否开过或参加过此团团
    // groupList userid
    this.data.product.grouptype = 1
    //如果此用户开过或参加过此团
    if (this.data.product.ismygroup == 1) {
      this.setData({
        iscantuan: 1
      })
    }
    
    //团长参团
    if (event == 2){
      var tuanitem = e.currentTarget.dataset.tuanitem;
      this.data.product.unigroupId = tuanitem.unigroupId;
      this.data.product.grouptype = 0
    }
    //分享参团
    if (event == 3) {
      this.data.product.unigroupId = this.data.unigroupId;
      this.data.product.grouptype = 0
    }
    console.log(this.data.product.product.isService);
    //是否为服务商品
    if (this.data.product.product.isService == 1) {
      this.data.product.isService = "1";
    }


    if (this.data.iscantuan == 1) {
      this.showZanTopTips(this.prompt, '你已经开或参过此团，请进入我的->我的拼团进行查看');
    } else {
      this.setData({
        showDialog: true,
      });
      try {
        wx.setStorageSync('GroupDetailsData', this.data);
      } catch (e) {
      }
      wx.navigateTo({
        url: '/pages/pay/SpellPay',
      })
    }


  },
  chooseSpan2:function(e){
    this.setData({
      specDialog: !this.data.specDialog,
    })
  },
  formSubmit: function (e) {
    this.setData({
      formId: e.detail.formId
    })
  },

  getPhoneNumber: function (e) {
    if (e.detail.encryptedData) {
      network._post_json(this, api.wxphone, { encryptedData: e.detail.encryptedData, iv: e.detail.iv, sessionKey: app.globalData.sessionKey }, bindSuccess);
    }
  },

  refresh(count) {
    this.setData({
      groupCount: this.data.groupCount - 1
    })
    if (parseInt(this.data.groupCount) <= 0) {
      this.setData({
        groupCount: 0
      })
    }

    var user = {
      avatarUrl: app.globalData.userAndTenantInfo.avatarUrl,
      nickName: app.globalData.userAndTenantInfo.nickName
    }
    this.data.spellGroup.user = user;
    this.setData({
      spellGroup: this.data.spellGroup
    })
  },
  // gotoCantuan: function (e) {
  //   console.log("// 先判断此用户是否开过或参加过此团团");
  //   var tuanitem = e.currentTarget.dataset.tuanitem;
  //   this.setData({
  //     spellGroupsId: tuanitem.spellGroupsId,
  //     sgCombId: tuanitem.sgCombId,
  //     nowclock: tuanitem.clock,
  //     userSpellGroupId: tuanitem.id,
  //     originator: tuanitem.originator
  //   })
   
  // },
  //查看更多
  groupMore: function (e) {
    if (this.data.count <= 0) {
      this.data.count = 1;
    }
    wx.setStorageSync('GroupDetailsData', this.data);
    wx.navigateTo({
      url: '/pages/product/SpellGroupMore?spellGroupsId=' + this.data.spellGroupId
    })
  }
}))
//门店
var successStore = function (that, res) {
  if (res.data.data) {
    that.setData({
      store: res.data.data,
    })
    app.globalData.store = res.data.data
  }
}
//校验当前选择的规格及数量是否可以购买
var isSelectedOk = function (that, product, counts) {

  //多规格
  if (product.specClass == 2) {
    if (that.data.isStore == 0) {
      if (that.data.product.confineCount != 0) {
        if (counts > that.data.product.confineCount) {
          //数量超出限购数量
          return -2;
        }
        return 1;
      }
      return 1;
    } else {
      if (that.data.product.confineCount != 0) {
        if (that.data.storeCount <= 0 || that.data.storeCount < counts) {
          //库存不足
          return -1;
        } else if (counts > that.data.product.confineCount) {
          //数量超出限购数量
          return -2;
        } else {
          return 1;
        }
      } else {
        if (that.data.storeCount <= 0 || that.data.storeCount < counts) {
          //库存不足
          return -1;
        } else {
          return 1;
        }
      }
    }
  } else {
    if (product.isStore == 0) {
      if (that.data.product.confineCount != 0) {
        if (counts > that.data.product.confineCount) {
          //数量超出限购数量
          return -2;
        }
        return 1;
      }
      return 1;
    } else {
      if (that.data.product.confineCount != 0) {
        if (product.storeCount <= 0 || product.storeCount < counts) {
          //库存不足
          return -1;
        } else if (counts > that.data.product.confineCount) {
          //数量超出限购数量
          return -2;
        } else {
          return 1;
        }
      } else {
        if (product.storeCount <= 0 || product.storeCount < counts) {
          //库存不足
          return -1;
        } else {
          return 1;
        }
      }
    }
  }
}
//获取多规格商品分类价格
var getProductPrice = function (that) {
  // console.log("获取多规格商品分类价格");
  console.log(that.data.product);

  //价格
  network._post_json(that, api.getProductPrice, { productId: that.data.product.product.id, specDetails1: that.data.specDetails1, specDetails2: that.data.specDetails2, specDetails3: that.data.specDetails3 }, successPrice);
}
var successPrice = function (that, res) {
  that.setData({
    count: 0
  })
  if (res.data.data) {
    that.setData({
      currentPrice: res.data.data.currentPrice ? res.data.data.currentPrice : 0,
      groupPrice: res.data.data.groupPrice ? res.data.data.groupPrice : 0,
      specId: res.data.data.specId,
      // limitCount: parseInt(res.data.data.limitCount),
      storeCount: parseInt(res.data.data.storeCount),
      isStore: res.data.data.isStore,
    })

  }
}
/**
 * 计算所选商品的总价
 */
// var allPrice = function (that, item, priceid) {
//   if (item.spellGroupsCombs && item.spellGroupsCombs.length > 0) {
//     if (priceid !== '' && priceid != undefined) {
//       var spec = item.spellGroupsCombs[priceid].specValue2
//     } else {
//       var spec = item.sgPrice
//     }
//     that.setData({
//       price: spec * that.data.count
//     })
//   } else {
//     that.setData({
//       price: item.sgPrice * that.data.count
//     })
//   }
// }

// 获取拼团详情结果
var detailsSuccess = function (that, res) {
  that.setData({
    groupList: [],
  })
  if (app.globalData.userId) {
    that.setData({
      userid: app.globalData.userId
    })
  } else {
    // 由于 openId 是网络请求，可能会在 Page.onLoad 之后才返回
    // 所以此处加入 callback 以防止这种情况
    app.userInfoCallback = res => {
      that.setData({
        userid: res.data.id
      })
    }
  }
  var arr = new Array();
  var listspecs = {};
  var initiallistspecs = {}

  if (res.data.data) {
    that.setData({
      product: res.data.data,
      groupPrice: res.data.data.product.groupPrice,
      currentPrice: res.data.data.product.currentPrice,
      detail: res.data.data.product.productdetail.detail.replace(/\<img/gi, '<img style="width:100%;height:auto" ').replace(/\white-space: nowrap;/gi, '').replace(/\white-space:nowrap;/gi, '')
      // listSpec: res.data.data.spellGroupsCombs,
      // listspecs: listspecs,
      // initiallistspecs: initiallistspecs
    })
    if (res.data.data.groupdetail){
      that.setData({
        groupList: res.data.data.groupdetail,
      })
      if (that.data.sharedUserId){
        for (var m = 0; m < res.data.data.groupdetail.length; m++) {
          console.log(app.globalData.userId);
          //分享unigroupId
          if (res.data.data.groupdetail[m].userId == that.data.sharedUserId) {
            if (that.data.product.ismygroup == 0){
              that.setData({
                isSharetuan: 1
              })
            }
            that.setData({
              unigroupId: res.data.data.groupdetail[m].unigroupId,
              
            })

          }
        }
      }
      

    }
    // WxParse.wxParse('details', 'html', , that, 0);
    if(that.data.groupList){
      countdown(that);
    }
    
    // if (that.data.product.spellGroupsCombs && !that.data.userSpellGroupId) {
    //   allPrice(that, that.data.product, that.data.listspecid);
    // }
    
    //此商品团长列表
    // network._post_json(that, api.getSpellGroupsDetail, { spellGroupsId: that.data.spellGroupId }, SDetailSuccess);
  }
  
}
// var SDetailSuccess = function (that, res) {
//   if (res.data.data) {
//     that.setData({
//       groupList: res.data.data.data,
//       allgroupList: res.data.data.data1.reverse()
//     })
//   }
  
// }
var startPay = function (that) {
  var product = {};
  var products = [];
  product.id = that.data.product.id;
  product.title = that.data.product.sgName;
  product.smallImgUrl = that.data.product.cutImg;
  product.conMode = that.data.product.conMode;
  product.count = that.data.count;
  if (that.data.userSpellGroupId && that.data.allgroupList.length>0) {
    //如果是用户参团(从分享里进入)
    product.userSpellGroupId = that.data.userSpellGroupId;
  }
  if (that.data.product.spellGroupsCombs && that.data.product.spellGroupsCombs.length > 0 && that.data.product.ruleType==2) {
    if (that.data.selectedSpec && (that.data.listspecid || that.data.listspecid == 0)) {
      product.price = that.data.RealListspec.specValue2;
      product.specId = that.data.product.spellGroupsCombs[that.data.listspecid].id;
      product.proprice = that.data.RealListspec.specValue1;
      product.specName = that.data.selectedSpec;
    } else if (that.data.selectedSpec && !that.data.listspecid && that.data.listspecid != 0) {
      product.price = that.data.product.sgPrice;
      product.proprice = that.data.product.proPrice;
      product.specId = that.data.product.spellGroupsCombs[0].id;
      product.specName = that.data.selectedSpec;
    }
  } else {
    product.price = that.data.product.sgPrice;
    product.proprice = that.data.product.proPrice;
  }


  products.push(product);
  try {
    wx.setStorageSync('spell_products', products)
  } catch (e) {
  }
  wx.navigateTo({
    url: '/pages/pay/SpellPay?spellGroupId=' + that.data.product.id
  })
}

var bindSuccess = function (that, res) {
  if (that.data.formId && app.globalData.userAndTenantInfo.mobile != res.data.data.mobile) {
    network._post_json(that, api.sendCoupn, { formId: that.data.formId, type: 2 }, sendCoupnSuccess);
  }

  app.globalData.userAndTenantInfo.mobile = res.data.data.mobile;
  that.setData({
    mobile: res.data.data.mobile
  })
}

// var ruleSuccess = function (that, res) {
//   that.setData({
//     spellGroup: res.data.data[0],
//     // price: res.data.data.proGroupPrice,
//     groupCount: parseInt(res.data.data[0].groupSuccCount) - parseInt(res.data.data[0].groupCount)
//   })
//   if (parseInt(that.data.groupCount) <= 0) {
//     that.setData({
//       groupCount: 0
//     })
//   }
//   allPrice(that, res.data.data[0]);
// }

var fxcsSuccess = function (that, res) {
  that.showZanToast('分享成功');
}

var FSuccess = function (that, res) {
  if (res.data.data.specType1 && !res.data.data.specType2 && !res.data.data.specType2) {
    res.data.data.spellGroupsComb.specDetails = res.data.data.specType1 + ':' + res.data.data.spellGroupsComb.specDetails1
  }
  if (res.data.data.specType2) {
    res.data.data.spellGroupsComb.specDetails = res.data.data.specType1 + ':' + res.data.data.spellGroupsComb.specDetails1 + '   ' + res.data.data.specType2 + ':' + res.data.data.spellGroupsComb.specDetails2
  }
  if (res.data.data.specType3) {
    res.data.data.spellGroupsComb.specDetails = res.data.data.specType1 + ':' + res.data.data.spellGroupsComb.specDetails1 + '   ' + res.data.data.specType2 + ':' + res.data.data.spellGroupsComb.specDetails2 + '   ' + res.data.data.specType3 + ':' + res.data.data.spellGroupsComb.specDetails3
  }

  if (res.data.data) {
    that.setData({
      groupsellDetail: res.data.data,
      specDetails: res.data.data.spellGroupsComb ? res.data.data.spellGroupsComb.specDetails : '',
      cantuanlist: res.data.data.spellGroupsDetails
    })

  }
  if (that.data.nowclock != "已经截止") {
    wx.navigateTo({
      url: '/pages/product/SpellGroupDetails?spellGroupId=' + that.data.spellGroupId + '&userSpellGroupId=' + that.data.userSpellGroupId
    })
  }


}

var bind = function (options) {
  if (options.shared) {
    wx.request({
      url: api.bindUserFormQRcode,
      data: {
        openId: app.globalData.openId,
        userId: app.globalData.userId,
        tenantId: app.globalData.tenantId,
        distributorId: options.shared,
      },
      method: 'POST',
      success: function (res) {
      }
    });
  }
}

var sendCoupnSuccess = function (that, res) { }